package com.aischool.webapp.teacher;

import java.util.Date;
import com.aischool.routes.RouteMapping;
import com.aischool.service.AiRollCallService;
import com.aischool.service.AiStudentService;
import com.aischool.utils.JsonCodeEnum;
import com.aischool.utils.JsonResult;
import com.jfinal.aop.Inject;

@RouteMapping(url = "/front/teacher/rollcall")
public class AiRollCallController extends BaseTeacherController {

	@Inject
	AiRollCallService aiRollCallService;
	@Inject
	AiStudentService aiStudentService;
	
	/**
	 * 获取全部学生、已点名学生、已离园学生
	 */
	public void getRollCall() {
		// 结果类
		JsonResult jr = new JsonResult();
		
		
		// 获取参数
		int login_class_id = this.getAttrForInt("login_class_id");	
		Date curdate = this.getDate("curdate");
		
		Object obj = aiStudentService.getStudents(login_class_id);
		jr.setDicKV("list_students", obj);
		obj = aiRollCallService.getRollCall(login_class_id, curdate);
		jr.setDicKV("list_rollcall", obj);
		
		jr.setEnum(JsonCodeEnum.Success);
		renderJson(jr.Dic);
	}
	
	public void postRollCall() {
		// 结果类
		JsonResult jr = new JsonResult();
		
		int ir = 0;
		int login_user_id = this.getAttrForInt("login_user_id");
		int login_class_id = this.getAttrForInt("login_class_id");	
		int tab_idx = getInt("tab_idx");
		Date cur_date = getDate("curdate");
		
		if (tab_idx == 0) {
			// 考勤点名
			String uncall_idvs = get("uncall_data", ""), change_idvs = get("change_data", ""), nocall_idvs = get("nocall_data", "");
			ir += aiRollCallService.saveRollCall(login_user_id, login_class_id, cur_date, uncall_idvs, change_idvs, nocall_idvs);
			
		}else if (tab_idx == 1) {
			// 离园提醒
			String unleave_idvs = get("unleave_data", "");
			ir += aiRollCallService.leaveCall(login_user_id, login_class_id, cur_date, unleave_idvs);
		}
		if (ir > 0) {
			Object obj = aiRollCallService.getRollCall(login_class_id, cur_date);
			jr.setDicKV("list_rollcall", obj);
			jr.setEnum(JsonCodeEnum.Success);
		}else {
			jr.setEnum(JsonCodeEnum.Faild);
		}
		renderJson(jr.Dic);
	}
}
